package com.dailyblue.java.spring.rocketmq.批量消息;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

public class 批量消息的生产 {
    public static void main(String[] args) throws Exception{
        DefaultMQProducer producer = new DefaultMQProducer("zhuoyue01");
        producer.setNamesrvAddr("192.168.160.88:9876");
        producer.start();
        List<Message> list = new ArrayList<>();
        for (int i = 1; i < 11; i++) {
            String topic = "TopicA";
            String tags = "piliang";
            String body = "piliang,index:"+i;
            Message message = new Message(topic,tags,body.getBytes(StandardCharsets.UTF_8));
            list.add(message);
        }
        SendResult result = producer.send(list);
        System.out.println(result);
        producer.shutdown();
    }
}
